package 搜狐发礼品;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int N = scanner.nextInt();
            int[] grades = new int[N];
            for (int i = 0; i < N; i++) {
                grades[i] = scanner.nextInt();
            }

            int[] bonus = new int[N];
            int[] r_bonus = new int[N];
            bonus[0] = 1;
            r_bonus[N - 1] = 1;

            for (int i = 1; i < grades.length; i++)
                bonus[i] = grades[i] > grades[i - 1] ? bonus[i - 1] + 1 : 1;

            for (int i = N - 1; i > 0; i--)
                r_bonus[i - 1] = grades[i - 1] > grades[i] ? r_bonus[i] + 1 : 1;

            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += Math.max(bonus[i], r_bonus[i]);
            }

            System.out.println(sum);
        }
    }
}